home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / Examples / PacMan / PacManView.h < prev    next >
Text File  |  1995-06-12  |  5KB  |  112 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. // This object is the guts of the whole game.  It is like a central clearing
  5. // house... it renders all the peices within itself.  Rather than having lots
  6. // of independent views that do theire rendering all throughout the game, this
  7. // view ties together a lot of player/ghost objects and has them render
  8. // themselves inside of itself.  This makes the drawing a bit more efficient
  9. // and allows allows easy programmatic control of which order things get drawn
  10. // in.  Since the images all use transparency, etc., this order is very
  11. // important.  The two main methods in here are the autoUpdate: method, which
  12. // is a giant state machine that handles the logic of the game, and the
  13. // updateSelf:: method that updates the screen from one animation frame to the
  14. // next.  drawSelf:: is  a less complex version of updateSelf:: because it
  15. // always renders the whole view, not just the things which have changed since
  16. // the last update.  By having two different methods, drawing is sped up at
  17. // the sacrifice of code clarity.  (Having two different rendering methods
  18. // gives better speed, but code complexity is nasty and the difficulty of
  19. // keeping both methods in sync so that they give identical results make for
  20. // a lot of work.)  I haven't yet found a good way to simplify the rendering
  21. // engine without slowing it down...if you have any suggestions, I would like
  22. // to hear them of course, but I've already tried quite a few things.
  23.  
  24. #import <gamekit/gamekit.h>
  25.  
  26. // states -- tells autoUpdate what to do
  27. #define BLINK_LEVEL 10    // when out of dots we do this
  28. #define READY 11        // READY on screen (starting a new level)
  29. #define DIEREADY 12        // READY on screen (after a die)
  30. #define DYING_PAC 13    // the Pac melts during this phase
  31. #define GAME_OVER GAMEOVER    // I forget which one to use, so define both
  32.  
  33. // Sizes of arrays used to determine which maze to use for a level
  34. // and the point value for a fruit on a particular level
  35. #define NUMSCREENS 24
  36. #define NUMFRUITVALS 16
  37.             
  38. #define WAITFORDEMO 600    // Wait x cycles before gameover to start demo
  39.  
  40. // values for "fruitOn" (besides YES and NO; these two are transitory states)
  41. #define DRAW    2        // do we put fruit on the screen?
  42. #define ERASE    3        // do we erase fruit from the screen?
  43.  
  44. // offset for drawing ghost/fruit point values.
  45. #define TEXTOFFSET (-10)
  46. #define WIPETEXT (-1)    // flag to undraw text scores
  47.  
  48. // when fruit gets erased
  49. #define ERASEFRUIT    (200 + (([controller level] <= 10) ? 10 * (10 - \
  50.     [controller level]) : 0) + timeToFruit)
  51.  
  52. // macro for zapping rectangle at specific coords
  53. #define ZAPRECT(r, x, y) NX_X(&(r)) = (x); NX_Y(&(r)) = (y); \
  54.     [dirtPile addRegion:&(r)]
  55. #define CLRRECT(r)  [dirtPile addRegion:&(r)]; \
  56.     [staticBuffer composite:NX_COPY fromRect:&(r) toPoint:&((r).origin)]
  57.  
  58. @interface PacManView:GameView
  59. {
  60.  
  61.     // various actors that get rendered in our view.
  62.     id  backGround2;
  63.     id  maze;
  64.     id  fruit[3];
  65.     id  player;
  66.     id  ghost[4];
  67.     id  gameOver[3];
  68.     
  69.     int begin;                // used as a counter for state transitions
  70.     BOOL erasePwr, eraseReady;    // erase power dot, ready text?
  71.     int fruitCount;            // counter to decide when to do fruit stuff
  72.     int timeToFruit;        // when to put next fruit up
  73.     int fruitOn;            // if fruit is out there...YES, NO, DRAW, or ERASE.
  74.     int numFruits;            // how many fruits put up in current level
  75.     int fruitPointCount, ftx, fty, fruitPoints, ftx2, fty2;
  76.     int ghostPointCount[4], gtx[4], gty[4], ghostPoints[4], gtx2[4], gty2[4];
  77.     NXPoint mazePos, myorigin;
  78.     NXRect eraseRect, textEraseRect, readyRect;
  79.     NXSize gameOverSize[3];
  80.     int  scale;
  81.     BOOL cheatMode; // in cheat mode?
  82.     GKTrackerId    ghostId, fruitId;    // bonus trackers
  83. }
  84.  
  85. - initFrame:(const NXRect *)frm;    // initialize instance
  86. - loadPix;                    // gameBrain calls this from appDidInit
  87. - ghost:(int)i;                // return ghost #i
  88. - autoUpdate:sender;        // sent by timer
  89.  
  90. - updateSelf:(NXRect *)rects :(int)rectCount;  //used by internals for speed
  91. - drawSelf:(NXRect *)rects :(int)rectCount;  // standard rendering method
  92. - keyDown:(NXEvent *)myevent;        // handle keyDown events.
  93. - setUpScreen;    // sets up screen from level start, calls -startScreen below.
  94. - startScreen;    // sets up screen without refilling all eaten dots.
  95. - restartGame;    // start game over.
  96. - restartGameForDemo:(BOOL)doingDemo;    // use to keep start game sound quiet
  97.             // in demo mode if that's what the user wants.
  98.  
  99. - blinkPowerDot;        // update static buffer where power dots are.
  100. - setBackgroundFile:(const char *)fileName andRemember:(BOOL)remember;
  101. - buildColorBackground;
  102. - rebuildStaticBuffer;
  103. - rebuildStaticAt:(NXRect *)rect;
  104.  
  105. - (int)scale;
  106. - setScale:(int)newScale;
  107.  
  108. - setGhostTracker:(GKTrackerId)tracker;
  109. - setFruitTracker:(GKTrackerId)tracker;
  110.  
  111. @end
  112.